package com.yanyeori.framework.redis.config;

import com.yanyeori.framework.redis.aspect.RedisLockAspect;
import com.yanyeori.framework.redis.util.RedisLockUtil;
import org.redisson.api.RedissonClient;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Redis锁配置
 *
 * @author chenkuan 2022/5/6
 */
@Configuration
public class RedisLockConfig {

    @Bean
    @ConditionalOnBean(RedissonClient.class)
    public RedisLockAspect redisLockAspect(RedissonClient redissonClient) {
        return new RedisLockAspect(redissonClient);
    }

    @Bean
    @ConditionalOnBean(RedissonClient.class)
    @ConditionalOnMissingBean(name = "redisLockUtil")
    public RedisLockUtil redisLockUtil(RedissonClient redissonClient) {
        return new RedisLockUtil(redissonClient);
    }
}
